package Interface.Windows;

import Interface.Panel.*;
import javax.persistence.EntityManagerFactory;
import javax.swing.JPanel;

/**
 *
 * @author USUARIO
 */
public class MainWindow extends javax.swing.JFrame {

    /**
     * Creates new form MainWindow
     */
    private EntityManagerFactory emf;
    public MainWindow(EntityManagerFactory emf, int rol) {
        initComponents();
        this.setLocationRelativeTo(null);
        this.emf = emf;
        jToolBar1.setFloatable(false);
        if (rol == 0){
            userToolBarBtn.setVisible(true);
            peasantToolBarBtn.setVisible(true);
            findPeasantToolBarBtn.setVisible(true);
            findUserToolBarBtn.setVisible(true);
            reportsToolBarBtn.setVisible(false);
            this.setTitle("SIRU - Administrador");
        }
        if (rol == 1){
            userToolBarBtn.setVisible(false);
            peasantToolBarBtn.setVisible(false);
            findPeasantToolBarBtn.setVisible(true);
            findUserToolBarBtn.setVisible(true);
            reportsToolBarBtn.setVisible(true);
            this.setTitle("SIRU - Asistente");
        }
    }
    
    public void setPanel(JPanel panel){
        contentPane.removeAll();
        contentPane = new JPanel();
        contentPane.add(panel);
        panel.setVisible(true);
        contentScrollPane.setViewportView(contentPane);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        userToolBarBtn = new javax.swing.JButton();
        peasantToolBarBtn = new javax.swing.JButton();
        findPeasantToolBarBtn = new javax.swing.JButton();
        findUserToolBarBtn = new javax.swing.JButton();
        reportsToolBarBtn = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        contentScrollPane = new javax.swing.JScrollPane();
        contentPane = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jToolBar1.setRollover(true);

        userToolBarBtn.setText("Usuario");
        userToolBarBtn.setFocusable(false);
        userToolBarBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        userToolBarBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        userToolBarBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userToolBarBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(userToolBarBtn);

        peasantToolBarBtn.setText("Campesino");
        peasantToolBarBtn.setFocusable(false);
        peasantToolBarBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        peasantToolBarBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        peasantToolBarBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                peasantToolBarBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(peasantToolBarBtn);

        findPeasantToolBarBtn.setText("Buscar Campesino");
        findPeasantToolBarBtn.setFocusable(false);
        findPeasantToolBarBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        findPeasantToolBarBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        findPeasantToolBarBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findPeasantToolBarBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(findPeasantToolBarBtn);

        findUserToolBarBtn.setText("Buscar Usuario");
        findUserToolBarBtn.setFocusable(false);
        findUserToolBarBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        findUserToolBarBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        findUserToolBarBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                findUserToolBarBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(findUserToolBarBtn);

        reportsToolBarBtn.setText("Reportes");
        reportsToolBarBtn.setFocusable(false);
        reportsToolBarBtn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        reportsToolBarBtn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        reportsToolBarBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reportsToolBarBtnActionPerformed(evt);
            }
        });
        jToolBar1.add(reportsToolBarBtn);

        jButton1.setText("Zonas");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        javax.swing.GroupLayout contentPaneLayout = new javax.swing.GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 934, Short.MAX_VALUE)
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 433, Short.MAX_VALUE)
        );

        contentScrollPane.setViewportView(contentPane);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 475, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(contentScrollPane))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(contentScrollPane)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void userToolBarBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userToolBarBtnActionPerformed
        PanelUser pu = new PanelUser(emf, this);
        setPanel(pu);
        this.setTitle("SIRU - Usuario");
    }//GEN-LAST:event_userToolBarBtnActionPerformed

    private void peasantToolBarBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_peasantToolBarBtnActionPerformed
        PanelPeasantRegister ppr = new PanelPeasantRegister(this.emf, this);
        setPanel(ppr);
        this.setTitle("SIRU - Campesino");
    }//GEN-LAST:event_peasantToolBarBtnActionPerformed

    private void findPeasantToolBarBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findPeasantToolBarBtnActionPerformed
        PeasantsListPanel plp = new PeasantsListPanel(emf);
        setPanel(plp);
        this.setTitle("SIRU - Buscar Campesino");
    }//GEN-LAST:event_findPeasantToolBarBtnActionPerformed

    private void findUserToolBarBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findUserToolBarBtnActionPerformed
        UsersListPanel ulp = new UsersListPanel(emf, this);
        setPanel(ulp);
        this.setTitle("SIRU - Buscar Usuario");
    }//GEN-LAST:event_findUserToolBarBtnActionPerformed

    private void reportsToolBarBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reportsToolBarBtnActionPerformed
        this.setTitle("SIRU - Reportes");
    }//GEN-LAST:event_reportsToolBarBtnActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        ZonesListPanel zlp = new ZonesListPanel(emf);
        setPanel(zlp);
        this.setTitle("SIRU - Buscar Zona");
    }//GEN-LAST:event_jButton1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel contentPane;
    private javax.swing.JScrollPane contentScrollPane;
    private javax.swing.JButton findPeasantToolBarBtn;
    private javax.swing.JButton findUserToolBarBtn;
    private javax.swing.JButton jButton1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton peasantToolBarBtn;
    private javax.swing.JButton reportsToolBarBtn;
    private javax.swing.JButton userToolBarBtn;
    // End of variables declaration//GEN-END:variables
}
